package es.agroservicio.Agroservicio.service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import es.agroservicio.Agroservicio.domain.Client;
import es.agroservicio.Agroservicio.repository.ClientsDAO;

@Component
public class ClientsManagerImpl implements ClientsManager {

	private static final long serialVersionUID = 1L;

	@Autowired
	private ClientsDAO clientsDao;

	public void setClientDao(ClientsDAO clientsDao) {
		this.clientsDao = clientsDao;
	}

	public List<Client> getClients() {

		return clientsDao.findAllOrderedByName();
	}

	public Map<String, String> getClientsIdNames() {
		
		Map<String, String> mapClients = new HashMap<String, String>();
		List<Client> clients = clientsDao.findAllOrderedByName();
		
		for(Client cli : clients)
			mapClients.put(cli.getDni(), cli.getSurname() + ", " + cli.getName());
		
		return mapClients;
	}

	public Client getClientById(String id) {
		return clientsDao.findById(id);
		
	}
}